#include "cmsis_os2.h"
#include "lvgl.h"


extern osMutexId_t LvglMutexHandle;

void StartLvglTask(void *argument)
{
    /* lvgl switch - 用于测试 */
    osMutexAcquire(LvglMutexHandle, osWaitForever);
    lv_obj_t* switch1 = lv_switch_create(lv_scr_act());
    lv_obj_center(switch1);
    osMutexRelease(LvglMutexHandle);

    // FS 写入测试
    // lv_fs_file_t fp;
    // char* buf_t = "Hello world!";
    // lv_fs_res_t ret = lv_fs_open(&fp, "0:/lv_test.txt", LV_FS_MODE_WR);
    // if(0 == ret)
    // {
    //     uint32_t writeen = 0;
    //     ret =  lv_fs_write(&fp, buf_t, 12, &writeen);
    //     lv_fs_close(&fp);
    // }

    // 读取测试
    lv_fs_file_t fp;
    char buf_t[50] = {0};
    lv_fs_res_t ret = lv_fs_open(&fp, "0:lv_test.txt", LV_FS_MODE_RD);
    if(0 == ret)
    {
        uint32_t read = 0;
        ret =  lv_fs_read(&fp, buf_t, 12, &read);
        lv_fs_close(&fp);
    }

    for(;;)
    {
        osMutexAcquire(LvglMutexHandle, osWaitForever);
        lv_timer_handler();
        osMutexRelease(LvglMutexHandle);
        osDelay(5);
    }
}
